import { DocumentObject, ObjInfo, cmdInvoker } from '@amcax/base';
import getEditCommand from '../config/getEditCommand';
import { docMgr, userEvents } from '@app-cad/module';
import { SKETCH_EVENT } from '../Constants';
import { enterSketch } from './sketchTools';

// 编辑打开
export function invokeEditCommand(documentObject: DocumentObject) {
  const { type, dxid, frame } = documentObject;
  const { invokeCmd } = cmdInvoker;

  if (type === 'Sketcher' && !docMgr.getCurrentSketchDxid()) {
    userEvents.emit(SKETCH_EVENT.SKETCH_ENTER_EDIT, true);
    docMgr.setLocalReferenceVisibility('ORIGIN', false);
    enterSketch({ frame, sketchId: dxid });

    return;
  }

  const objInfo: ObjInfo = { ...documentObject, children: [] };

  const cmd = getEditCommand(objInfo);

  if (cmd == null || cmd.noEdit) {
    return;
  }
  invokeCmd(cmd.command, objInfo);
}
